package org.example.mytest.newMapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.mytest.newentity.users;
import org.example.mytest.newentity.warehouse;

import java.util.List;

@Mapper
public interface WarehouseMapper extends BaseMapper<warehouse> {
    @Select("select * from warehouse where WarehouseID=#{warehouseid}")
    warehouse findby(int id);
    @Select("SELECT w.WarehouseID, w.Location, w.UserID " +
            "FROM warehouse w")
    @Results({
            @Result(property = "warehouseid", column = "WarehouseID"),
            @Result(property = "location", column = "Location"),

            @Result(property = "userid", column = "UserID"),
            @Result(column = "userid", property = "users", javaType = users.class,
                    one = @One(select = "org.example.mytest.newMapper.UsersMapper.findby"))
    })
    List<warehouse> getWarehouseAndUsers();

    @Select("SELECT w.WarehouseID, w.Location, w.UserID " +
            "FROM warehouse w")
    @Results({
            @Result(property = "warehouseid", column = "WarehouseID"),
            @Result(property = "location", column = "Location"),
            @Result(property = "managerid", column = "ManagerID"),
            @Result(property = "userid", column = "UserID"),
            @Result(column = "userid", property = "users", javaType = users.class,
                    one = @One(select = "org.example.mytest.newMapper.UsersMapper.findby")),
            @Result(column = "warehouseid", property = "companies", javaType = List.class,
                    many= @Many(select = "org.example.mytest.mapper.ScoreMapper.findscoreby"))
    })
    List<warehouse> getWarehouseAndUsersandcompanies();
}